<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>公共设备列表</title>
	<link rel="stylesheet" type="text/css" href="../common/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../common/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="../common/demo.css">
	<script type="text/javascript" src="../common/jquery.min.js"></script>
	<script type="text/javascript" src="../common/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../common/common.js"></script>
	<script type="text/javascript" src="../common/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>

<table id="dg" title="公共设备列表" style="width: 99%;height:630px"
	   data-options="rownumbers:true,
						singleSelect:true,
						autoRowHeight:true,
						pagination:true,
						pageSize:20,
						url:'/manage/device/list',
						method:'get',
						toolbar:'#tb'">
	<thead>
	<tr>
		<th data-options="field:'id',width:100,hidden:'true'">设备id</th>
		<th data-options="field:'deviceName',width:100">设备名称</th>
		<th data-options="field:'deviceNum',width:100">设备数量</th>
		<th data-options="field:'state',width:100,
					formatter: function (state, row, index) {
			       return deletedState(state); <!--value就是数据库具体的值-->
			    }">设备状态</th>
	</tr>
	</thead>
</table>
<div id="tb" style="padding:2px 5px;">
	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="searchA()">Search</a>
</div>
</body>
<script type="text/javascript">
	$(function(){
		searchA();
	})
	function searchA(){
		var data = {
		};
		var pager = $('#dg').datagrid({
			queryParams: data,
			//双击事件
			onDblClickRow :function(rowIndex,rowData){
					//getSelected()
				}
		}).datagrid('getPager');	// get the pager of datagrid
		pager.pagination({
			buttons:[{
				iconCls:'icon-edit',
				handler:function(){
					//getSelected();
				}
			}]
		});
		pager.pagination().find('a.l-btn').tooltip({
			content: function(){
				var cc = $(this).find('span.l-btn-icon').attr('class').split(' ');
				var icon = cc[1].split('-')[1];
				return icon + ' page';
			}
		});
		$('#approve').window('close');
		$('#addForm').window('close');
	}

	function getSelected(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$('#approve').window('open');
			$('#update').form('load',{
				id:row.id,
				floorId:row.floorId,
				unitId:row.unitId,
				roomId:row.roomId,
				state:row.state
			});
		}
	}
	function submitForm(){
		var id = $('#id').val();
		var data = {
			id: id
		};
		$('#update').form('submit', {
			url: "/manage/house/update",
			queryParams: data,
			onSubmit: function(){

			},
			success: function(data){
				var data = eval('(' + data + ')');
				if(data.code==10000){
					$.messager.alert('成功',"提交成功");
					var pager = $('#dg').datagrid('reload');
				}else{
					$.messager.alert('失败',data.code+"："+data.message);
				}

			},
			error: function(){
				$.messager.alert('失败',"联系管理员");
			}
		});
		$('#approve').window('close');
	}

	function add(){
		$('#addForm').window('open');
	}

	function addUser(){
		var platForm = $('#addPlatForm').val();
		var userName = $('#addUserName').val();
		var password = $('#addPassword').val();
		var data = {
				platForm:platForm,
				password:password,
				userName:userName,
				state:1
		};
		$('#add').form('submit', {
			url: "/manage/user/add",
			queryParams: data,
			onSubmit: function(){

			},
			success: function(data){
				var data = eval('(' + data + ')');
				if(data.code==10000){
					$.messager.alert('成功',"提交成功");
					var pager = $('#dg').datagrid('reload');
				}else{
					$.messager.alert('失败',data.code+"："+data.message);
				}

			},
			error: function(){
				$.messager.alert('失败',"联系管理员");
			}
		});
		$('#addForm').form('clear');
		$('#addForm').window('close');
	}

	function deletedState( deleted ){
		if("0" == deleted){
			return "正常";
		}else{
			return "损坏";
		}

	}
	function stateState( state ){
		if("0" == state){
			return "管理员";
		}else{
			return "业主";
		}

	}
	</script>
</html>